package com.goods.controller.business;

import com.goods.business.service.SupplierService;
import com.goods.common.error.BusinessException;
import com.goods.common.model.business.Supplier;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.SupplierVO;
import com.goods.common.vo.system.PageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "来源模块-物资来源相关接口")
@RestController
@RequestMapping("/business/supplier")
public class SupplierController {

  @Autowired
  private SupplierService supplierService;


  @ApiOperation(value = "物资来源信息列表")
  @GetMapping("/findSupplierList")
  public ResponseBean findSupplierList(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                       @RequestParam(value = "pageSize") Integer pageSize,
                                       SupplierVO supplierVO){
    PageVO<SupplierVO> supplierVOPageVO = supplierService.findSupplierList(pageNum,pageSize,supplierVO);
    return ResponseBean.success(supplierVOPageVO);
  }

  @ApiOperation(value = "添加物资来源信息")
  @PostMapping("/add")
  public ResponseBean add(@RequestBody @Validated SupplierVO supplierVO){
    supplierService.add(supplierVO);
    return ResponseBean.success();
  }

  @ApiOperation(value = "编辑物资来源信息页面",notes = "点击编辑按钮后显示编辑页面")
  @GetMapping("/edit/{id}")
  public ResponseBean edit(@PathVariable Long id) throws BusinessException {
    SupplierVO supplierVO = supplierService.edit(id);
    return ResponseBean.success(supplierVO);
  }

  @ApiOperation(value = "修改物资来源信息",notes = "点击确定按钮后提交修改信息")
  @PutMapping("/update/{id}")
  public ResponseBean update(@PathVariable Long id,@RequestBody @Validated SupplierVO supplierVO){
    supplierService.update(id,supplierVO);
    return ResponseBean.success();
  }

  @ApiOperation(value = "删除物资来源")
  @DeleteMapping("/delete/{id}")
  public ResponseBean delete(@PathVariable Long id){
    supplierService.delete(id);
    return ResponseBean.success();
  }
}
